import _thread as thread
import time


def work(tid, count, write_lock, status_lock):
    for n in range(count):
        write_lock.acquire()
        print('%s => %s' % (tid, n))
        write_lock.release()
        time.sleep(0.5)
    status_lock.acquire()


if __name__ == '__main__':
    count = 3
    write_lock = thread.allocate_lock()
    status_locks = []
    for tid in range(2):
        status_lock = thread.allocate_lock()
        thread.start_new_thread(work, (tid, count, write_lock, status_lock))
        status_locks.append(status_lock)

    # wait for threads
    while True:
        if all([lock.locked() for lock in status_locks]):
            print('all done')
            break
        time.sleep(0.1)
